package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.User;
import com.zr.service.FindsorceServicehh;
import com.zr.serviceImpl.FindsorceServiceImplhh;
//修改学生成绩
public class UpdescoreControllerhh extends HttpServlet {
	FindsorceServicehh upde=new FindsorceServiceImplhh();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	req.setCharacterEncoding("utf8");
	resp.setCharacterEncoding("utf8");
	HttpSession session = req.getSession();
	User u  = (User)session.getAttribute("User"); //获取存在session的用户
	int tid = u.getTid();//获取用户的tid
	String tname = upde.findTnameByTid(tid);
	int sid  = Integer.parseInt(req.getParameter("sid"));
	String cname = req.getParameter("cname");
	String oldscore = req.getParameter("oldscore");
	String newscore = req.getParameter("newscore");
	String nr = oldscore+"分修改为"+newscore+"分";
	String zt = "未审批";
	Date d = new Date();
	SimpleDateFormat sim = new SimpleDateFormat("YYYY年MM月dd日hh时mm分");
	String sj = sim.format(d);
	boolean flag = upde.updescore(sid, tname,newscore,cname, nr, zt, sj);
	PrintWriter pw= resp.getWriter();
	if(flag){
		pw.write("1");
	}else{
		pw.write("0");
	}
	pw.flush();
	pw.close();
}

}
